import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class TextDemo {
    public static void buckeSort(int[] array){
        if(array==null || array.length<=1){
            return ;
        }
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        for(int value : array){
            if(value>max) max = value;
            if(value<min) min = value;
        }
        int range = max-min+1;
        int buckeAmount = 100;
        double gap = range*1.0/(buckeAmount-1);
        int[][] buckes = new int[buckeAmount][];
        for(int value : array){
            int index = (int)((value-min)/gap);
            buckes[index] = add(buckes[index],value);
        }
        int index = 0;
        for(int i = 0;i<buckeAmount;i++){
            if(buckes[i]==null || buckes[i].length<=1) continue;

            insertSort(buckes[i]);
            System.arraycopy(buckes[i],0,array,index,buckes[i].length);
            index+=buckes[i].length;
        }


    }
    private static int[] add(int[] array,int num){
        if(array==null || array.length<=1){
            return null;
        }
        int[] newArr = Arrays.copyOf(array,array.length+1);
        newArr[array.length] = num;
        return newArr;
    }
    private static void insertSort(int[] array,int num){
        for(int i = 1;i<array.length;i++){
            int currentNumber = array[i];
            int j = i-1;
            while(j>=0 && currentNumber<array[j]){
                array[j+1] = array[j];
                j--;
            }
            array[j+1] = currentNumber;
        }
    }
    public static void radixSort(int[] nums){
       int max = Integer.MIN_VALUE;
       int min = Integer.MAX_VALUE;
       for(int value : nums){
           if(max<value) max = value;
       }
       int maxDigitLength = 0;
       while(max!=0){
           maxDigitLength++;
           max/=10;
       }
       int[] counting = new int[19];
       int[] result = new int[nums.length];
       int dex = 1;
       for(int i = 0;i<maxDigitLength;i++){
           for(int value : nums){
               int radix = value/dex%10+9;
               counting[radix]++;
           }
           for(int j = 1;j<counting.length;j++){
               counting[j]+=counting[j-1];
           }
           for(int j = nums.length-1;j>=0;j--){
               int raidx = nums[j]/dex%10+9;
               result[--counting[raidx]] = nums[j];
           }
           System.arraycopy(result,0,nums,0,nums.length);
           Arrays.fill(counting,0);
           dex*=10;
       }
    }
    public static void radixSortNor(int[] array){
        if(array==null || array.length<=1){
            return ;
        }
        int max = Integer.MIN_VALUE;
        for(int value : array){
            if(max<value) max = value;
        }
        int maxDigitLength = 0;
        while(max!=0){
            maxDigitLength++;
            max/=10;
        }
        int[] counting = new int[10];
        int[] result = new int[array.length];
        int dev = 1;
        for(int i = 0;i<maxDigitLength;i++){
            for(int value : array){
                int radix = value/dev%10;
                counting[radix]++;
            }
            for(int j = 1;j<counting.length;j++){
                counting[j] += counting[j-1];
            }
            for(int j = 0;j<array.length;j++){
                int radix = array[j]/dev%10;
                result[--counting[radix]] = array[j];
            }
            System.arraycopy(result,0,array,0,array.length);
            Arrays.fill(counting,0);
            dev*=10;
        }
    }
    public static void main(String[] args) {
        int[] nums = new int[] {3,6,1,0};
        if(nums.length==1){
            System.out.println(0);;
        }
        Map<Integer,Integer> map = new HashMap<>();
        for(int i = 0;i<nums.length;i++){
            map.put(nums[i],i);
        }
        int swapIndex = 0;
        int lastIndex = nums.length-1;
        boolean flag = true;
        while(flag){
            flag = false;
            for(int i = 1;i<=lastIndex;i++){
                if(nums[i]<nums[i-1]){
                    flag = true;
                    swap(nums,i,i-1);
                    swapIndex = i;
                }
            }
            lastIndex = swapIndex;
        }
        flag =  nums[nums.length-1]>=(2*nums[nums.length-2]);
        if(flag){
            System.out.println(map.get(nums[nums.length - 1]));
        }else{
            System.out.println(-1);
        }
    }
    public static void countingSort(int[] array){
        if(array==null || array.length<=1){
            return ;
        }
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        for(int value : array){
            if(value>max) max = value;
            if(value<min) min = value;
        }
        int range = max-min+1;
        int[] counting = new int[range];
        for(int value : array){
            counting[value-min]++;
        }
        for(int i = 1;i<counting.length;i++){
            counting[i]+=counting[i-1];
        }
        int[] result = new int[array.length];
        for(int i = array.length-1;i>=0;i--){
            result[--counting[array[i]-min]] = array[i];
        }
        for(int i = 0;i<array.length;i++){
            array[i] = result[i];
        }
    }
  public static void countingSortNor(int[]array){
      if(array==null || array.length<=1){
          return ;
      }
      int max = Integer.MIN_VALUE;
      int min = Integer.MAX_VALUE;
      for(int value : array){
          if(max<value) max = value;
          if(min>value) min = value;
      }
      int range = max-min+1;
      int[] counting = new int[range];
      for(int value : array){
          counting[value-min]++;
      }
      int prevCount = 0;
      for(int i = 0;i<counting.length;i++){
          prevCount+=counting[i];
          counting[i] = prevCount-counting[i];
      }
      int[] result = new int[array.length];
      for(int value : array){
          result[counting[value-min]] = value;
          counting[value-min]++;
      }
      for(int i = 0;i<array.length;i++){
          array[i] = result[i];
      }
  }


    public static void mergeSortNor(int[] array){
        if(array.length<=1 || array==null){
            return ;
        }
        int[] result = mergeSort(array,0,array.length-1);
        for(int i = 0;i<result.length;i++){
            array[i] = result[i];
        }
    }
    public static void mergeSort(int[] array){
        if(array==null || array.length<=1){
            return ;
        }
        int[] result = new int[array.length];
        mergeSort(array,0,array.length-1,result);
    }
    private static void mergeSort(int[] array,int start,int end,int[] result){
        if(start==end){
            return ;
        }
        int middle = (start+end)/2;
        mergeSort(array,start,middle,result);
        mergeSort(array,middle+1,end,result);
        merge(array,start,end,result);
    }
    private static int[] mergeSort(int[] array,int start,int end){
        if(start==end) return new int[]{array[start]};
        int middle = (start+end)/2;
        int[] left = mergeSort(array,start,middle);
        int[] right = mergeSort(array,middle+1,end);

        return merge(left,right);
    }
    private static void merge(int[] array,int start,int end,int[] result){
        int middle = (start+end)/2;
        int index1 = start;
        int index2 = middle+1;
        while(index1<=middle && index2<=end){
            if(array[index1]<=array[index2]){
                result[index1+index2-middle-1] = array[index1++];
            }else{
                result[index1+index2-middle-1] = array[index2++];
            }
        }
        while(index1<=middle){
            result[index1+index2-middle-1] = array[index1++];
        }
        while(index2<=end){
            result[index1+index2-middle-1] = array[index2++];
        }
        while(start<=end){
            array[start] = result[start++];
        }
    }
    private static int[] merge(int[] arrayL,int[] arrayR){
        int[] result = new int[arrayL.length+arrayR.length];
        int indexL = 0;
        int indexR = 0;
        while(indexL<arrayL.length && indexR<arrayR.length){
            if(arrayL[indexL]<=arrayR[indexR]){
                result[indexL+indexR] = arrayL[indexL++];
            }else{
                result[indexL+indexR] = arrayR[indexR++];
            }
        }
        while(indexL<arrayL.length){
            result[indexL+indexR] = arrayL[indexL++];
        }
        while(indexR<arrayR.length){
            result[indexL+indexR] = arrayR[indexR++];
        }
        return result;
    }
    public static void quickSort(int[] array){
        quickSort(array,0,array.length-1);
    }
    private static void quickSort(int[] array,int left,int right){
        if(left>=right){
            return;
        }
        int pivot = partitionHeroa(array,left,right);
        quickSort(array,left,pivot-1);
        quickSort(array,pivot+1,right);
    }
    private static int partition(int[] array,int start,int end){
        int pivot = array[start];
        int left = start+1;
        int right = end;
        while(left<right){
            while(left<right && array[left]<=pivot) left++;
            while(left<right && array[right]>=pivot) right--;
            if(left!=right){
                swap(array,left,right);
                left++;
                right--;
            }
        }
        if(left==right && array[right]>pivot) right--;
        swap(array,start,right);
        return right;
    }
    private static int partitionHeroa(int[] array,int start,int end){
        int pivot = array[start];
        int left = start+1;
        int right = end;
        while(left<right){
            while(left<right && array[left]<=pivot) left++;

                if(left!=right){
                    swap(array,left,right);
                    right--;
                }
        }
        if(left==right && array[right]>pivot){
            right--;
        }
        if(right!=start) swap(array,start,right);
        return right;
    }
    public static void HeapSort(int[] array){
        buildmaxHeap(array);
        for(int i = array.length-1;i>0;i--){
            swap(array,0,i);
            maxHeapify(array,0,i);
        }
    }
    private static void buildmaxHeap(int[] array){
        for(int i = array.length/2-1;i>=0;i--){
            maxHeapify(array,i,array.length);
        }
    }
    private static void maxHeapify(int[] array,int i,int heapSize){
        int last = i;
        int left = i*2+1;
        int right = left+1;
        if(left<heapSize && array[left]>array[last]){
            last = left;
        }
        if(right<heapSize && array[right]>array[last]){
            last = right;
        }
        if(last!=i){
            swap(array,i,last);
            maxHeapify(array,last,heapSize);
        }
    }
    public static void shellSort(int[] array){
        for(int gap = array.length/2;gap>0;gap/=2){
            for(int currentIndex = gap;currentIndex<array.length;currentIndex++){
                int currentNumber = array[currentIndex];
                int prevIndex = currentIndex-gap;
                while(prevIndex>=0 && array[prevIndex]>currentNumber){
                    array[prevIndex+gap] = array[prevIndex];
                    prevIndex-=gap;
                }
                array[prevIndex+gap] = currentNumber;
            }
        }
    }
    public static void shellSortNor(int[] array){
        for(int gap = array.length/2;gap>0;gap/=2){
            for(int StartgroupIndex = 0;StartgroupIndex<gap;StartgroupIndex++){
                for(int currentIndex = StartgroupIndex+gap;currentIndex<array.length;currentIndex+=gap){
                    int prevIndex = currentIndex-gap;
                    int currentNumber = array[currentIndex];
                    while(prevIndex>=0 && array[prevIndex]>currentNumber){
                        array[prevIndex+gap] = array[prevIndex];
                        prevIndex-=gap;
                    }
                    array[prevIndex+gap] = currentNumber;
                }
            }

        }
    }
    public static void insertSort(int[] array){
        for(int i = 1;i<array.length;i++){
            int j = i-1;
            int currentNumber = array[i];
            while(j>=0 && currentNumber<array[j]){
                array[j+1] = array[j];
                j--;
            }
            array[j+1] = currentNumber;
        }
    }
    public static void insertSortNor(int[] array){
        for(int i = 1;i<array.length;i++){
            int j = i;
            while(j>=1 && array[j-1]>array[j]){
                swap(array,j,j-1);
                j--;
            }
        }
    }
    public static void selectionSort(int[] array){
        int minIndex = 0;
        int maxIndex = 0;
        for(int i = 0;i<array.length/2;i++){
            minIndex = i;
            maxIndex = i;
            for(int j = i+1;j<array.length-i;j++){
                if(array[maxIndex]<array[j]) maxIndex = j;
                if(array[minIndex]>array[j]) minIndex = j;
            }
            if(minIndex==maxIndex) return ;
            swap(array,minIndex,i);
            if(maxIndex==i){
                maxIndex = minIndex;
            }
            int lastIndex = array.length-i-1;
            swap(array,maxIndex,lastIndex);
        }
    }
    public static void bubbleSort(int[] array){
        int swapIndex = 0;
        int lastIndex = array.length-1;
        boolean flag = true;
        while(flag){
            flag = false;
            for(int i = 0;i<lastIndex;i++){
                if(array[i]>array[i+1]){
                    swap(array,i,i+1);
                    flag = true;
                    swapIndex = i;
                }
            }
            lastIndex = swapIndex;
        }
    }


    private static void swap(int[] array,int x,int y){
        int tem = array[x];
        array[x] = array[y];
        array[y] = tem;
    }
}
